define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    
    //设置弹窗宽高
    Fast.config.openArea = ['46%', '50%'];
    
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'finance/subjects/index' + location.search,
                    add_url: 'finance/subjects/add',
                    edit_url: 'finance/subjects/edit',
                    del_url: 'finance/subjects/del',
                    table: 'finance_subjects',
                }
            });

            var table = $("#table");

            //修改快速搜索显示文字
            $.fn.bootstrapTable.locales[Table.defaults.locale]['formatSearch'] = function(){return "输入ID快速搜索"};

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                pagination: true,
                pageSize: 500,
                commonSearch: false,
                search: true,
                showToggle: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'name', title: __('Name'), operate: false},
                        {field: 'desc', title: __('Desc'), operate: false, formatter: function (value, row, index) {
                            return value ? value : '-';
                        }},
                        {field: 'income', title: __('Income'), operate: false},
                        {field: 'spending', title: __('Spending'), operate: false},
                        {field: 'balance', title: __('Balance'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'edit',
                                    text: '编辑',
                                    classname: 'btn btn-xs btn-success btn-editone',
                                    icon: 'fa fa-pencil',
                                    refresh: true
                                },
                                {
                                    name: 'del',
                                    text: '删除',
                                    classname: 'btn btn-xs btn-danger btn-delone',
                                    icon: 'fa fa-trash',
                                    refresh: true
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});